package com.goldcn.sys.model.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.HashMap;
import java.util.Map;

/**
 * json工具类
 * @author 
 *
 */
public class JsonUtil {
    /**
     * bean转json
     * @param obj
     * @return
     */
    public static String toJson(Object obj){
        if(obj == null){
            return null;
        }
        Gson gson = new GsonBuilder().serializeNulls().create();
        return gson.toJson(obj);
    }
    
    @SuppressWarnings("rawtypes")
	public static Map toMap(String jsonStr) 
    {
        Gson gson = new Gson();
        Map map = gson.fromJson(jsonStr, HashMap.class);
        
        return map;
    }
    
}